@extends('admin.layouts.app')
@section('css')
        <!-- Custombox css -->
       
        <link href="{{asset('admin/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css')}}" rel="stylesheet">
         
@endsection 

@section('content')

                        <div class="row">
                            <div class="col-sm-12">
                                <h4 class="page-title">工单管理</h4>
                                <ol class="breadcrumb">
                                    <li><a href="{{url('zadmin')}}">系统</a></li>
                                    <li><a href="{{url('zadmin/task')}}">工单管理</a></li>
                                    <li class="active">修改工单</li>
                                </ol>
                            </div>
                        </div>
                        
                        <div class="row">
                        	<div class="col-lg-12">
                        		<div class="card-box">
                                    <div class="row">
                            <h2 class="m-t-0 header-title">预约信息</h2>
                           
                        </div>
                            <hr/>
                             @if(session('rs') || $errors->any())
                              <div class="alert alert-{{session('rs')['status']}}">
                        @if($errors->any())
                            @foreach($errors->messages() as $msg )
                                {{$msg[0]}}
                            @endforeach
                        @endif
                                {{ session('rs')['msg'] }}
                              </div>
                              @endif
                        			<div class="row">

			                        	<div class="col-md-12">
                                  
                           
                            <div class="row">
                                 <form method="post" action="{{url('zadmin/booking/update',$data->id)}}" enctype="multipart/form-data">

                                     {{ csrf_field()}}
                                <div class="col-lg-12">
                                   
                                <div class="panel panel-border panel-default">
                                    
                                    <div class="panel-body">
                                        <div class="row">
                                           
                                            


                                            
                                        </div>
                                   
                                        <div class="col-md-4">
    <div class="form-group ">
    <label class="col-md-4">预约人<span class="text-danger">*</span></label>
    <div class="col-md-8">
     <input class="form-control" name="name" value="{{$data->name}}" required=""/>
 </div>
     </div>
</div>

<div class="col-md-4">
    <div class="form-group ">
    <label class="col-md-4">电话<span class="text-danger">*</span></label>
    <div class="col-md-8">
     <input class="form-control" name="phone" value="{{$data->phone}}" required=""/>
 </div>
     </div>
</div>
                                        <div class="row">
                                            <div class="form-group col-md-4">
                                                <label class="col-md-4">预约日期<span class="text-danger">*</span></label>
                                                <div class="col-md-8"> 
                                                <input class="form-control date" name="booking_time" value="{{$data->booking_time}}"  /> 
                                                </div>
                                            </div>
                                            <div class="form-group col-md-4">
                                                <label class="col-md-4">送修里程<span class="text-danger">*</span></label>
                    <div class="input-group col-md-8">
                        <input name="miles" class="form-control" value="{{$data->miles}}" />
                        <span class="input-group-btn">
                        <button type="button" class="btn waves-effect waves-light btn-primary">公里</button>
                        </span>
                    </div> 
                                            </div>
                                           
                                            

                                            
                                            <div class="form-group col-md-6">
                                                <label class="col-md-3">故障信息</label>
                                                <div class="col-md-9">
                                                <input class="form-control " name="bug_info" value="{{$data->bug_info}}" /> 
                                            </div>
                                           

                                            
                                            

                                        </div>
                                    </div>

                                    <div class="form-group text-center">                                                
                                    <button type="submit" class="btn btn-success waves-effect waves-light">更新</button>
                                </div>
                                </div>
                            </div>
</form>
                             

                             

                             

                           
                                
                                                    
                        </div>




                                

                                        

                                    </div>

                                </div>


                            </div>


                            
                        
                       
                                </div>
			                        	
			                        </div>

                             
			                        
                        			
                        		</div>
                                
                            </div> <!-- end col -->

                            
                        </div>
@endsection
                        
                        
                        

                  
            
    @section('modal')        
      
    @endsection        
       

           



    
        @section('js')
       

<script type="text/javascript" src="{{asset('admin/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js')}}"></script>
<script type="text/javascript" src="{{asset('admin/plugins/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js')}}" charset="UTF-8"></script>
<script type="text/javascript">
$(document).ready(function () {  
    $(".serviceitem tr").find("select").select2();
    $('.departitem tr').find("select").select2();

   


    
});    
   

    
   

    

    $('.date').datetimepicker({
        format: "yyyy-mm-dd",
        autoclose: true,
        todayBtn: true,
        startDate: new Date()
       
    });

    $('#client_id').on('change',function(){
        var client_id = $(this).val();
        var url = "{{url('api/cars')}}";
       
        $.get(url,{'client_id':client_id},function(rs){
            if(rs.status==true) {
                var opt = '';
                $.each(rs.data,function(k,v){
                    opt = opt+'<option value="'+v.id+'">'+v.car_num+'</option>'
                });
                $('#car_id').append(opt);
            }
        })
    });

    $(document).on('change','.service_type',function(){
        var _this = $(this);
        var type_id = _this.val();
        var url = "{{url('api/services')}}";
        $.get(url,{'type_id':type_id},function(rs){
            if(rs.status==true) {
                var service = _this.parents('tr').find('.service_id');
                service.empty();
                var opt = '<option value="">请选择</option>';
                $.each(rs.data,function(k,v){
                    opt += '<option value="'+v.id+'" data-price="'+v.price+'">'+v.name+'</option>'; 
                });
                 service.append(opt);
                
            }
        })
    });

    $(document).on('change','.service_id',function(){
        var _this = $(this);
        var price = _this.find("option:selected").data('price')
        //alert(price);
        _this.parents('tr').find('.service_price').val(price);
        
        
    });

    $(document).on('change','.depart_cate',function(){
        var _this = $(this);
        var cate_id = _this.val();
        var url = "{{url('api/departs')}}";
        $.get(url,{'cate_id':cate_id},function(rs){
            if(rs.status==true) {
                var depart = _this.parents('tr').find('.depart_id');
                depart.empty();
                var opt = '<option value="">请选择</option>';
                $.each(rs.data,function(k,v){
                    opt += '<option value="'+v.id+'" data-price="'+v.out_price+'" data-num="'+v.store_num+'">'+v.name+'</option>'; 
                });
                 depart.append(opt);
                
            }
        })
    });

    $(document).on('change','.depart_id',function(){
        var _this = $(this);
        var price = _this.find("option:selected").data('price');
        var  num = _this.parents('tr').find('.depart_num').val();
        var store_num = _this.find("option:selected").data("num");
        if(store_num<5) {
            alert('库存小于5，请及时补充');
        }
        subTotal = num*price;
        _this.parents('tr').find('.total_price').val(subTotal);
        
    });

    $(document).on('click','.total_price',function(){
        var _this = $(this);
        var num   = _this.parents('tr').find('.depart_num').val();
        var price = _this.parents('tr').find('.depart_id option:selected').data("price");
        
        if(price==undefined) {
            alert('请选择配件');return ;
        }
        _this.val(price*num);
    });

    $(document).on('click','.service_price',function(){
        var _this = $(this);
        
        var price = _this.parents('tr').find('.service_id option:selected').data("price");
        //alert(price);
        if(price==undefined) {
            alert('请选择配件');return ;
        }
        _this.val(price);
    });
    




         

         
        </script>
@endsection
    
